package cn.cdeden.knowledge.controller.online.search;

import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.knowledge.domain.dto.*;
import cn.cdeden.knowledge.domain.vo.FileAnalysisDataVo;
import cn.cdeden.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
/**
 * @ProjectName : ecm_svn
 * @Package : com.cdyd.ecm.modules.online.factory.search
 * @ClassName : SearchFilesInfoFactory
 * @Description : // 方法工厂
 * @Version : 1.0
 */
@Component
public class SearchFilesInfoFactory {
    private static final String key = "SearchFiles_";

    @Autowired
    private Map<String, SearchFilesInfo> infoMap;


    /**
     * @Description // 统一的文件搜索
     * @param type
     * @param infoDto
     * @param pageable
     * @return com.cdyd.ecm.base.PageInfo<com.cdyd.ecm.tree.FilesTree>
     **/
    public TableDataInfo<FilesTree> searchInfo(String type , SearchFilesInfoDto infoDto, Pageable pageable){
        type = key + type;
        boolean b = infoMap.containsKey(type);
        if (b) {
            return infoMap.get(type).searchInfo(infoDto, pageable);
        }else {
            throw new RuntimeException("错误的文件类型无法去查询数据");
        }
    }



    /**
     * @Description // 查询该节点下的文件信息
     * @param query
     * @return java.util.List<com.cdyd.ecm.tree.FilesTreeDto>
     **/
    public List<FilesTree> queryNodeFileInfo(PortalQueryParam query, LoginUser userDto){
        String type = key + query.getLibraryType();
        boolean b = infoMap.containsKey(type);
        if (b) {
            return infoMap.get(type).queryNodeFileInfo(query, userDto);
        }else {
            throw new RuntimeException("错误的文件类型无法去查询数据");
        }
    }



    /**
     * @Description // 获取文件格式 分类信息
     * @param type
     * @return java.util.List<com.cdyd.ecm.sys.domain.dto.FileFormatSuffixDto>
     **/
    public List<FileFormatSuffixDto> getFileFormatInfo(String type){
        type = key + type;
        boolean b = infoMap.containsKey(type);
        if (b) {
            return infoMap.get(type).getFileFormatInfo();
        }else {
            throw new RuntimeException("错误的文件类型无法去查询数据");
        }
    }

    public List<FileAnalysisDataVo> getNewFileAnalysisData(Map<String, List<String>> resultMap, String type) {
        type = key + type;
        boolean b = infoMap.containsKey(type);
        if (b) {
            return infoMap.get(type).getNewFileAnalysisData(resultMap);
        }else {
            throw new RuntimeException("错误的文件类型无法去查询数据");
        }
    }



    public TableDataInfo<FilesTree> queryNodeFileInfoPage(PortalQueryParam query, LoginUser userDto, Pageable pageable){
        String type = key + query.getLibraryType();
        boolean b = infoMap.containsKey(type);
        if (b) {
            return infoMap.get(type).queryNodeFileInfoPage(query, userDto,pageable);
        }else {
            throw new RuntimeException("错误的文件类型无法去查询数据");
        }
    }
}
